package com.designpattern.strategy;

/**
 * 选择排序算法。
 */
public class Sorter2<T> {
    //初步
    public  void sort(T[] arr,MyComparator<T> comparator) {
        for (int i = 0; i < arr.length; i++) {
            int minPos = i;
            for (int j = i + 1; j < arr.length; j++) {
                minPos = comparator.compare(arr[j] , arr[minPos])  == -1? j : minPos;
            }
            swap(arr, i, minPos);
        }
    }

    public void swap(T[] arr, int i, int j) {
        T tem = arr[i];
        arr[i] = arr[j];
        arr[j] = tem;
    }


}
